package com.irdstudio.efp.esb.api.rest.dxm;

import java.math.BigDecimal;
import java.util.Objects;

import javax.servlet.http.HttpServletRequest;

import com.irdstudio.efp.esb.common.constant.*;
import org.apache.rocketmq.common.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.irdstudio.basic.framework.core.constant.PrdInfoConstant;
import com.irdstudio.basic.framework.core.constant.SDicCertTypeEnum;
import com.irdstudio.basic.framework.core.exception.BizException;
import com.irdstudio.basic.framework.core.util.DateUtility;
import com.irdstudio.basic.framework.core.util.MessageRuleCheckUtil;
import com.irdstudio.basic.framework.core.util.StringUtil;
import com.irdstudio.basic.framework.core.util.TimeUtil;
import com.irdstudio.basic.framework.core.util.TraceUtil;
import com.irdstudio.efp.basic.framework.mq.client.producer.MQProducerMessageClient;
import com.irdstudio.efp.basic.framework.mq.constant.TagEnums;
import com.irdstudio.efp.basic.framework.mq.constant.TopicEnums;
import com.irdstudio.efp.cus.service.facade.CusIndivService;
import com.irdstudio.efp.cus.service.vo.CusIndivVO;
import com.irdstudio.efp.esb.api.bean.dxm.ReqLoanAdjustLimitBean;
import com.irdstudio.efp.esb.api.bean.dxm.RespLoanAdjustLimitBean;
import com.irdstudio.efp.esb.api.common.EsbRespServiceBeanCreator;
import com.irdstudio.efp.esb.api.util.SDicMappingServer;
import com.irdstudio.efp.esb.common.constant.EsbBizEnums;
import com.irdstudio.efp.esb.common.constant.EsbSysHeadEnums;
import com.irdstudio.efp.esb.common.constant.MsLoanConstant;
import com.irdstudio.efp.esb.common.constant.SDicClientConstant;
import com.irdstudio.efp.esb.common.constant.dxm.AdjustMode;
import com.irdstudio.efp.esb.common.constant.dxm.DxmEnum;
import com.irdstudio.efp.esb.common.server.req.EsbReqServiceBean;
import com.irdstudio.efp.esb.common.server.resp.EsbRespServiceBean;
import com.irdstudio.efp.limit.service.facade.LmtAdjustThirdService;
import com.irdstudio.efp.limit.service.vo.LmtAdjustThirdVO;
import com.irdstudio.efp.nls.common.constant.PrdAdaptedSoltEnums;
import com.irdstudio.efp.nls.common.constant.QueueTaskEnums;
import com.irdstudio.efp.nls.service.facade.queue.NlsProcessBizService;
import com.irdstudio.efp.nls.service.vo.queue.NlsProcessBizVO;

/**
 * 额度调整申请服务接口
 * @author  qiuyf
 * @since 2019年3月7日 下午2:39:12
 * @version 1.0
 */
@RestController
@RequestMapping("/esb")
public class LoanAdjustLimitController {

	private static Logger logger = LoggerFactory.getLogger(LoanAdjustLimitController.class);

	@ModelAttribute("esbReqServiceBean")
	public EsbReqServiceBean getReqEsbHeadBean(HttpServletRequest request) {
		logger.info("获取ESB请求对象，校验 ESB请求系统头和请求应用头对象开始");
		EsbReqServiceBean esbReqServiceBean = (EsbReqServiceBean) request.getAttribute("esbReqServiceBean");
		return esbReqServiceBean;
	}

	@ModelAttribute("reqLoanAdjustLimitBean")
	public ReqLoanAdjustLimitBean getReqEsbBodyBean(HttpServletRequest request) {
		logger.info("获取额度调整申请服务接口请求对象，校验额度调整申请服务接口请求体对象开始");
		String esbReqBody = (String) request.getAttribute("esbReqBody");
		return JSONObject.parseObject(esbReqBody, ReqLoanAdjustLimitBean.class);
	}

	@PostMapping("/SERVICE_30220010_01")  
	public EsbRespServiceBean doRecv(@Validated @ModelAttribute("esbReqServiceBean") EsbReqServiceBean esbReqServiceBean, BindingResult br1,
			@Validated @ModelAttribute("reqLoanAdjustLimitBean") ReqLoanAdjustLimitBean reqLoanAdjustLimitBean, BindingResult br2, Exception exception) {
		String bdSnId   = reqLoanAdjustLimitBean.getBaiduSnId();
		String adjAmtId = reqLoanAdjustLimitBean.getAdjAmtIdNo();
		String globalSerno = esbReqServiceBean.getSysHead().getGlblSrlNo();
		String repeatRqsBss = reqLoanAdjustLimitBean.getRepeatRqsBss();
		String certCode = reqLoanAdjustLimitBean.getIDCertNo();
		String prdId = reqLoanAdjustLimitBean.getProdCd();
		TraceUtil.setTraceId(globalSerno);
		logger.info("额度调整申请服务接口处理开始----------会话ID：" + bdSnId + "------------调额申请流水号（唯一标记一次调额）:" + adjAmtId);
		try {
			// 1. 通过切面校验额度调整申请参数是否正确，如不正确则返回错误信息
			if (Objects.nonNull(exception)) {
				throw exception;
			}

			// 2. 字段合规性校验
			this.reqBeanCheck(reqLoanAdjustLimitBean);

			// 3. 调用中台服务，查询并判断
			/** 
			 * 1）请求方需要保证永远唯一，响应方据此判断是否重复请求
			 * 2）全局流水号是否已被使用
			 * 3）调额申请流水号是否已存在调额申请记录
			 */
			LmtAdjustThirdVO domain = new LmtAdjustThirdVO();
			domain.setBdReqSn(repeatRqsBss);
			domain = lmtAdjustThirdService.queryByBdReqSn(domain);
			if(Objects.nonNull(domain)) {
				throw new BizException(EsbBizEnums.RetCodeEnum.REPEAT.getVALUE(), "重复请求标识：" + "【" + repeatRqsBss + "】" + "，已发送过请求，请核查！");
			}
			//需要重新new一次对象，避免空指针出现
			domain = new LmtAdjustThirdVO();
			domain.setGlobalSerno(globalSerno);
			domain = lmtAdjustThirdService.queryByGlobalSerno(domain);
			if(Objects.nonNull(domain)) {
				throw new BizException(EsbBizEnums.RetCodeEnum.REPEAT.getVALUE(), "全局流水号：" + "【" + globalSerno + "】" + "，已经被使用，请核查！");
			}
			//需要重新new一次对象，避免空指针出现
			domain = new LmtAdjustThirdVO();
			domain.setAdjAmtId(adjAmtId);
			domain = lmtAdjustThirdService.queryByAdjAmtId(domain);
			if(Objects.nonNull(domain)) {
				throw new BizException(EsbBizEnums.RetCodeEnum.REPEAT.getVALUE(), "调额申请流水号：" + "【" + adjAmtId + "】" + "，已经存在调额申请记录，请核查！");
			}
			
			//通过身份证号、证件类型获取客户信息
			CusIndivVO cusIndivVO = this.getCusInfo(certCode);
			
			// 4. 将额度调整申请数据，插入到第三方额度调整申请表
			LmtAdjustThirdVO lmtAdjustThirdVO = new LmtAdjustThirdVO();
			/** 调整申请流水号 = 会话ID */
			lmtAdjustThirdVO.setAdjSeq(bdSnId);
			/** 请求方需要保证永远唯一，响应方据此判断是否重复请求 */
			lmtAdjustThirdVO.setBdReqSn(repeatRqsBss);
			/** 版本号 add @date 2019/04/18 */
			lmtAdjustThirdVO.setVerNo(reqLoanAdjustLimitBean.getVerNo());
			/** 渠道编号 */
			lmtAdjustThirdVO.setChannelNo(reqLoanAdjustLimitBean.getChanFlg());
			/** 产品编号 */
			lmtAdjustThirdVO.setPrdId(prdId);
			lmtAdjustThirdVO.setPrdCode(reqLoanAdjustLimitBean.getProdCd());
			//产品名称
			lmtAdjustThirdVO.setPrdName(PrdInfoConstant.PrdCode.getValue(prdId));
			//客户编号
			lmtAdjustThirdVO.setCusId(cusIndivVO.getCusId());
			//客户姓名
			lmtAdjustThirdVO.setCusName(cusIndivVO.getCusName());
			/** 身份证号 */
			lmtAdjustThirdVO.setCertCode(certCode);
			//证件类型为：居民身份证
			lmtAdjustThirdVO.setCertType(SDicCertTypeEnum.IDCARD.getValue());
			/** 最高学历 */
			lmtAdjustThirdVO.setBdEducation(StringUtil.isNullorBank(reqLoanAdjustLimitBean.getHighEdu()) ? null : 
				SDicMappingServer.getLocalSysDicVal(SDicClientConstant.DEGREE, reqLoanAdjustLimitBean.getHighEdu()));
			/** 年龄 */
			lmtAdjustThirdVO.setBdAge(reqLoanAdjustLimitBean.getAgeCnt());
			/** 贷中人群分层 */
			lmtAdjustThirdVO.setBdPostLoanLevel(reqLoanAdjustLimitBean.getBDPostLoanLvl());
			/** 贷前人群分层 */
			lmtAdjustThirdVO.setBdPreaCustSeg(StringUtil.isNullorBank(reqLoanAdjustLimitBean.getBDPreLoanLvl()) ? null : reqLoanAdjustLimitBean.getBDPreLoanLvl());
			/** 调整类型 */
			lmtAdjustThirdVO.setBdScenarioType(reqLoanAdjustLimitBean.getAdjAmtTp());
			/** 调整方式 */
			lmtAdjustThirdVO.setAdjMode(reqLoanAdjustLimitBean.getAdjMd());
			/** 调整说明 */
			lmtAdjustThirdVO.setAdjComment(reqLoanAdjustLimitBean.getAdjRsnCd());
			/** 黑名单类型 */
			lmtAdjustThirdVO.setBdBlackListType(StringUtil.isNullorBank(reqLoanAdjustLimitBean.getBlklistTp()) ? null : reqLoanAdjustLimitBean.getBlklistTp());
			/** 请求时间 */
			lmtAdjustThirdVO.setApplyDate(DateUtility.formatDateTime17To19(reqLoanAdjustLimitBean.getRqsTmstmp()));
			/** 首次申请时间 */
			lmtAdjustThirdVO.setBdYxdDate(StringUtil.isNullorBank(reqLoanAdjustLimitBean.getPrimAppTm()) ? null : DateUtility.formatDateTime14To19(reqLoanAdjustLimitBean.getPrimAppTm()));
			/** 调整结果额度 = 调额后额度 */
			lmtAdjustThirdVO.setAdjResultLmt(new BigDecimal(reqLoanAdjustLimitBean.getAdjAfterAmt()));
			/** 调整基础额度 = 调额前额度 */
			lmtAdjustThirdVO.setAdjBasicLmt(new BigDecimal(reqLoanAdjustLimitBean.getAdjPreAmt()));
			/** 内部多头分（身份证） */
			lmtAdjustThirdVO.setBdPrcidNormalScoreExp3(StringUtil.isNullorBank(reqLoanAdjustLimitBean.getBDIdCertScr()) ? null : reqLoanAdjustLimitBean.getBDIdCertScr());
			/** 度小满 B模型分  */
			lmtAdjustThirdVO.setBdDxmbScore(reqLoanAdjustLimitBean.getBDBScr());
			/** 调额申请流水号 */ 
			lmtAdjustThirdVO.setAdjAmtId(reqLoanAdjustLimitBean.getAdjAmtIdNo());
			/** 当前逾期期数  */
			lmtAdjustThirdVO.setBdJxjdueTimes(StringUtil.isNullorBank(reqLoanAdjustLimitBean.getCurrOvdueTerm()) ? null : reqLoanAdjustLimitBean.getCurrOvdueTerm());
			/** 最近三个月额度利用率 */
			lmtAdjustThirdVO.setBdUtilityRatio(StringUtil.isNullorBank(reqLoanAdjustLimitBean.getUtlzRate()) ? null : reqLoanAdjustLimitBean.getUtlzRate());
			/** 内部多头分（手机）*/
			lmtAdjustThirdVO.setBdPhoneNormalScoreExp3(StringUtil.isNullorBank(reqLoanAdjustLimitBean.getBDMblNoScr()) ? null : reqLoanAdjustLimitBean.getBDMblNoScr());
			/** 内部多头分（百度帐号） */
			lmtAdjustThirdVO.setBdBidNormalScoreExp3(StringUtil.isNullorBank(reqLoanAdjustLimitBean.getBDAcctNoScr()) ? null : reqLoanAdjustLimitBean.getBDAcctNoScr());
			/** 全局流水号 */
			lmtAdjustThirdVO.setGlobalSerno(globalSerno);
			/** 合作平台id 平台ID */
			lmtAdjustThirdVO.setPlatfmid(StringUtil.isNullorBank(esbReqServiceBean.getSysHead().getPlafmID()) ? 
					MsLoanConstant.PlafmEnum.BD.VALUE : esbReqServiceBean.getSysHead().getPlafmID());
			/** 合作平台用户id  平台用户ID */
			lmtAdjustThirdVO.setPlatfmusrid(StringUtil.isNullorBank(esbReqServiceBean.getSysHead().getPlafmUsrID()) ? 
					reqLoanAdjustLimitBean.getChanFlg() + reqLoanAdjustLimitBean.getIDCertNo() : esbReqServiceBean.getSysHead().getPlafmUsrID());
			/** 额度调整状态设置为“处理中” */
			lmtAdjustThirdVO.setAdjStatus(DxmEnum.LoanAdjustSts.DEALING.getVALUE());
			/** 插槽阶段“额度调整”*/
			lmtAdjustThirdVO.setSoltStage(PrdAdaptedSoltEnums.SoltStageEnum.LIMITADJ.getVALUE());
			/** 创建时间 */
			lmtAdjustThirdVO.setCreateTime(TimeUtil.getCurrentDateTime());
			//通知类型 add @date 2019/06/10 
			lmtAdjustThirdVO.setAdvType(reqLoanAdjustLimitBean.getAdvType());
			// add by ludayong 2019/11/15 【数据权限】增加主管机构赋值
			// 主管机构
			lmtAdjustThirdVO.setMainBrId(InstitutionEnums.InstitutionEnum.GZYHZHYHZXSCTD1.getCode());
			int num1 = lmtAdjustThirdService.insertLmtAdjustThird(lmtAdjustThirdVO);

			// 插入网贷业务过程表
			NlsProcessBizVO inNlsProcessBizVo = new NlsProcessBizVO();
			/** 申请流水号 */
			inNlsProcessBizVo.setApplySeq(adjAmtId); 
			/** 客户编号 */
			inNlsProcessBizVo.setCusId(cusIndivVO.getCusId());
			/** 客户名称 */
			inNlsProcessBizVo.setCusName(cusIndivVO.getCusName());
			/** 产品ID */
			inNlsProcessBizVo.setPrdId(prdId);
			/** 产品代码 */
			inNlsProcessBizVo.setPrdCode(prdId);
			/** 产品名称 */
			inNlsProcessBizVo.setPrdName(PrdInfoConstant.PrdCode.getValue(prdId));
			/** 挂起次数 */
			inNlsProcessBizVo.setHangTimes(QueueTaskEnums.QueueHangTimesEnum.INITIALIZE.getTimes());
			/** 队列任务状态 */
			inNlsProcessBizVo.setQueueTaskState(QueueTaskEnums.QueueTaskStateEnum.EXECUTORY.getCode());
			/** 创建时间 */
			inNlsProcessBizVo.setCreateTime(DateUtility.getCurrAppDateTimeString());
			/** 最后修改时间 */
			inNlsProcessBizVo.setLastModifyTime(DateUtility.getCurrAppDateTimeString());
			/** 创建日期 */
			inNlsProcessBizVo.setCreateDate(DateUtility.getCurrAppDateStr());
			// add by ludayong 2019/11/15 【数据权限】增加经办机构赋值
			// 经办机构
			inNlsProcessBizVo.setNlsOperOrgid(InstitutionEnums.InstitutionEnum.GZYHZHYHZXSCTD1.getCode());
			int num2 = nlsProcessBizService.insertNlsProcessBiz(inNlsProcessBizVo);

			// 5. 组装返回的响应报文
			if(-1 == num1 || -1 == num2) {
				throw new BizException("插入数据表异常!");
			}else {
				producerService.sendMsg(new Message(TopicEnums.QUEUE_TASK_LIMIT_TOPIC.getTopicId(), TagEnums.TAG_QUEUE_LIMIT_TASK.getTagId(), 
						adjAmtId, JSON.toJSONString(lmtAdjustThirdVO).getBytes("UTF-8")));
				return EsbRespServiceBeanCreator.buildesbRespServiceBean(esbReqServiceBean,
						buildRespLoanAdjustLimitBean(EsbBizEnums.RetCodeEnum.SUCCESS.getVALUE(), "网贷系统已成功接收额度调整申请请求信息。",reqLoanAdjustLimitBean.getAdjAmtIdNo()).toString(),
						EsbSysHeadEnums.RetStEnum.SUCCESS.getCode(), EsbBizEnums.RetCodeEnum.SUCCESS.getVALUE(), "网贷系统已成功接收额度调整申请请求信息。");
			}
		} catch (BizException e) {
			logger.error("***********调用额度调整申请服务接口处理失败**************"+e.getMessage());
			String errorCode = EsbBizEnums.RetCodeEnum.FAILURE.getVALUE();
			if(EsbBizEnums.RetCodeEnum.REPEAT.getVALUE().equals(e.getErrorCode())) {
				errorCode = EsbBizEnums.RetCodeEnum.REPEAT.getVALUE();
			}
			return EsbRespServiceBeanCreator.buildesbRespServiceBean(esbReqServiceBean,
					buildRespLoanAdjustLimitBean(errorCode, e.getMessage(),reqLoanAdjustLimitBean.getAdjAmtIdNo()).toString(),
					EsbSysHeadEnums.RetStEnum.FAILURE.getCode(), errorCode , e.getMessage());
		} 
		catch (Exception e) {
			logger.error("***********调用额度调整申请服务接口处理失败**************"+e.getMessage());
			return EsbRespServiceBeanCreator.buildesbRespServiceBean(esbReqServiceBean,
					buildRespLoanAdjustLimitBean(EsbBizEnums.RetCodeEnum.FAILURE.getVALUE(), e.getMessage(),reqLoanAdjustLimitBean.getAdjAmtIdNo()).toString(),
					EsbSysHeadEnums.RetStEnum.FAILURE.getCode(), EsbBizEnums.RetCodeEnum.FAILURE.getVALUE(), e.getMessage());
		} finally {
			logger.info("额度调整申请服务接口处理结束----------会话ID：" + bdSnId + "------------调额申请流水号（唯一标记一次调额）:" + adjAmtId);
			TraceUtil.clear();
		}

	}

	private void reqBeanCheck(ReqLoanAdjustLimitBean reqLoanAdjustLimitBean) throws BizException {
		/**
		 * 1.获取需要验证的字段
		 */
		//调额后额度
		BigDecimal lmtAft = new BigDecimal(reqLoanAdjustLimitBean.getAdjAfterAmt());
		//调额前额度
		BigDecimal lmtBef = new BigDecimal(reqLoanAdjustLimitBean.getAdjPreAmt());
		//调整方式
		String adjModel = reqLoanAdjustLimitBean.getAdjMd();
		//身份证号码
		String certCode = reqLoanAdjustLimitBean.getIDCertNo();
		//首次申请时间
		String fstApplyTime = reqLoanAdjustLimitBean.getPrimAppTm();
		//请求时间
		String applyTime = reqLoanAdjustLimitBean.getRqsTmstmp();
		//贷中人群分级
		String bdPostLoanLvl = reqLoanAdjustLimitBean.getBDPostLoanLvl();
		//百度身份证评分
		String bdIdCertScr = reqLoanAdjustLimitBean.getBDIdCertScr();
		//度小满B模型评分 
		String bdBScr = reqLoanAdjustLimitBean.getBDBScr();
		//额度利用率
		String utlZRate = reqLoanAdjustLimitBean.getUtlzRate();
		//百度手机号评分
		String bDMblNoScr = reqLoanAdjustLimitBean.getBDMblNoScr(); 
		//百度账号评分
		String bDAcctNoScr= reqLoanAdjustLimitBean.getBDAcctNoScr();
		
		/**
		 * 	2. 字段合规性校验
		 */
		/* 身份证号码 */
		MessageRuleCheckUtil.validateIdNo18(certCode);
		/* 年龄 */
		if(StringUtil.isStrNotEmpty(reqLoanAdjustLimitBean.getAgeCnt())) {
			MessageRuleCheckUtil.checkInteger(reqLoanAdjustLimitBean.getAgeCnt(), "年龄");
		}
		/* 首次申请时间 */
		if(StringUtil.isStrNotEmpty(fstApplyTime)) {
			MessageRuleCheckUtil.checkDate("首次申请时间", fstApplyTime, "yyyyMMddHHmmss");
		}
		/* 请求时间格式 */
		//  MessageRuleCheckUtil.checkDate("请求时间", applyTime, "yyyyMMddHHmmss");
		MessageRuleCheckUtil.checkDouble(lmtAft+"", "调额后额度");
		MessageRuleCheckUtil.checkDouble(lmtBef+"", "调额前额度");
		
		//当是提额申请时，调额后额度必须大于调额前额度
		if(AdjustMode.TIE.getValue().equals(adjModel) && lmtAft.compareTo(lmtBef) == -1) {
			throw new BizException("调整方式为【提额】，调整后额度【"+ lmtAft + "】，需大于调额前额度【" + lmtBef + "】");
		}
		//当是降额申请时，调额后额度必须小于调额前额度
		if(AdjustMode.JIANGE.getValue().equals(adjModel) && lmtAft.compareTo(lmtBef) == 1) {
			throw new BizException("调整方式为【降额】，调整后额度【"+ lmtAft + "】，需小于调额前额度【" + lmtBef + "】");
		}
		//当调额后额度等于调额前额度，视为无效的调额申请操作
		if(lmtAft.compareTo(lmtBef) == 0) {
			throw new BizException("调整后额度【"+ lmtAft + "】，与调额前额度【" + lmtBef + "】相等，调额申请为无效操作！");
		}
		if(!"-9999".equals(bdPostLoanLvl)){
			if(Integer.parseInt(bdPostLoanLvl) < 1 || Integer.parseInt(bdPostLoanLvl) > 99) {
				throw new BizException("贷中人群分级【" + bdPostLoanLvl + "】，不在[1, 99]范围中！");
			}
		}
		if(!"-9999".equals(bdIdCertScr)){
				if(StringUtil.isStrNotEmpty(bdIdCertScr) && (Integer.parseInt(bdIdCertScr) < 0 || Integer.parseInt(bdIdCertScr) > 100)) {
				throw new BizException("百度身份证评分【" + bdIdCertScr + "】，不在[0, 100]范围中！");
			}
		}
		if(!"-9999".equals(bdBScr)) {
			if (StringUtil.isStrNotEmpty(bdBScr) && (Integer.parseInt(bdBScr) < 230 || Integer.parseInt(bdBScr) > 890)) {
				throw new BizException("度小满B模型评分【" + bdBScr + "】，不在[230, 890]范围中！");
			}
		}
		if(!"-9999".equals(utlZRate)) {
			if (StringUtil.isStrNotEmpty(utlZRate) && (Double.parseDouble(utlZRate) < 0.00 || Double.parseDouble(utlZRate) > 1.00)) {
				throw new BizException("额度利用率【" + utlZRate + "】，不在[0.00, 1.00]范围中！");
			}
		}
		if(!"-9999".equals(bDMblNoScr)) {
			if(StringUtil.isStrNotEmpty(bDMblNoScr) && (Integer.parseInt(bDMblNoScr) < 0 || Integer.parseInt(bDMblNoScr) > 100)) {
				throw new BizException("百度手机号评分【" + bDMblNoScr + "】，不在[0, 100]范围中！");
			}
		}
		if(!"-9999".equals(bDAcctNoScr)) {
			if (StringUtil.isStrNotEmpty(bDAcctNoScr) && (Integer.parseInt(bDAcctNoScr) < 0 || Integer.parseInt(bDAcctNoScr) > 100)) {
				throw new BizException("百度账号评分【" + bDAcctNoScr + "】，不在[0, 100]范围中！");
			}
		}
	}
	

	private CusIndivVO getCusInfo(String certCode) {
		CusIndivVO cusIndivVO = new CusIndivVO();
		cusIndivVO.setCertType(SDicCertTypeEnum.IDCARD.getValue());
		cusIndivVO.setCertCode(certCode);
		cusIndivVO = cusIndivService.queryByCust(cusIndivVO);
		if(Objects.isNull(cusIndivVO)) {
			logger.error("通过身份证号【"+ certCode + "】，无法获取客户信息！");
			cusIndivVO = new CusIndivVO();
		}
		return cusIndivVO;
	}
	
	private static RespLoanAdjustLimitBean buildRespLoanAdjustLimitBean(String retStCd, String rtnMsg, String adjAmtId) {
		logger.debug("组装额度调整申请服务接口响应bean开始...调额申请流水号（唯一标记一次调额）：" + adjAmtId);
		RespLoanAdjustLimitBean respLoanAdjustLimitBean = new RespLoanAdjustLimitBean();
		respLoanAdjustLimitBean.setRetCd(retStCd);
		respLoanAdjustLimitBean.setRetMsg(rtnMsg);
		logger.debug("{*********组装额度调整申请服务接口响应bean结束！调额申请流水号（唯一标记一次调额）：" + adjAmtId + ",返回码:" + retStCd + ",返回信息:" + rtnMsg + "**********}");
		return respLoanAdjustLimitBean;
	}

	@Autowired
	@Qualifier("lmtAdjustThirdService")
	private LmtAdjustThirdService lmtAdjustThirdService;

	@Autowired
	@Qualifier("producerService")
	private MQProducerMessageClient producerService;

	@Autowired
	@Qualifier("nlsProcessBizService")
	private NlsProcessBizService nlsProcessBizService;
	
	@Autowired
	@Qualifier("cusIndivService")
	private CusIndivService cusIndivService;

}
